package com.cat.graphTheory;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-number-of-vertices-to-reach-all-nodes/
 * @create 2025/9/20 10:28
 * @since JDK17
 */

public class Solution17 {
    public List<Integer> findSmallestSetOfVertices(int n, List<List<Integer>> edges) {
        int[] in = new int[n];
        int m = edges.size();
        List<Integer> ans = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            int to = edges.get(i).get(1);
            in[to]++;
        }

        for (int i = 0; i < n; i++) {
            if (in[i] == 0) {
                ans.add(i);
            }
        }
        return ans;
    }
}
